doctype html
html(lang='en')
  head
    meta(charset='UTF-8')
    meta(http-equiv='Content-Type', content='text/html; charset=UTF-8')
    meta(name='renderer', content='webkit')
    title 注册
    link(rel='stylesheet', href='/css/base/ck_base.css', media='screen')    
    link(rel='stylesheet', href='/css/register.css', media='screen')
    script(src='/js/jquery-1.8.0.min.js')
    script(src='/js/user/util.js')      
  body
    .header
      h1.hdLogo
        img(src='/images/lan.png')
      a.hdIntro(href='#') 用户注册
    .content
      .contentMiddle
        form.registerView
          input#province(type='hidden')
          input#city(type='hidden')
          input#zone(type='hidden')          
          input#school(type='hidden')
          input#cls(type='hidden')
          input#sms(type='hidden')
          .registerBar
            .barLeft 用户名：
            .barRight
              input.registerInput#username(name='username',type='text', placeholder='请输入用户名')
          .registerBar
            .barLeft 昵称：
            .barRight
              input.registerInput#nickname(name='nickname',type='text', placeholder='请输入昵称')
          .registerBar
            .barLeft 手机号：
            .barRight
              input.registerInput#mobile(name='mobile',type='text', placeholder='请输入手机号码')
          .registerBar
            .barLeft 验证码：
            .barRight.code
              input.registerInput#code(name='code',type='text', placeholder='请输入验证码')
            #getCode.codeButton 获取验证码
            #waitCode.codeButton.disabled 请等待(60)
          .registerBar
            .barLeft 密码：
            .barRight
              input.registerInput#password(name='password',type='password', placeholder='请输入密码')
          .registerBar
            .barLeft 是否在校：
            .barRight.removeBar
              input(type='radio',checked, name="onSchool",onclick='showSchoolSelection()')
              | 在校 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              input(type='radio',name="onSchool",onclick='hideSchoolSelection()')
              | 不在校
          div#cascader_school
          .registerButton 注 册
    script(type='text/javascript').
      var checkMobile = function(mobile) {
      var regular = /^[(86)|0]?(13\d{9})|(15\d{9})|(17\d{9})|(18\d{9})$/g;
      if (!regular.test(mobile)) {
      return false;
      }
      return true;
      };      
      var data = !{JSON.stringify(_city)};
      var cascader_city = JSON.parse(data);      
      var marginFix = (document.body.clientWidth) / 2;
      $(".registerView").css("right", marginFix - 200 + "px")
      function placeholderSupport() {
      return 'placeholder' in document.createElement('input');
      }
      var showSchoolSelection = function () {
      $(".schoolSelection").show();
      }
      var hideSchoolSelection = function () {
      $(".schoolSelection").hide();
      }
      $("#getCode").click(function () {
      var mobile = $("#mobile").val();
      if (checkMobile(mobile) == false) {
      $.alertBoxy({ message: '请填写正确的手机号！' });
      return;
      }      
      var codeTime;
      $("#waitCode").show();
      $("#getCode").hide();
      var startSecond = 59;
      codeTime = setInterval(function () {
      var html = "请等待("+startSecond+")";
      $("#waitCode").html(html);
      startSecond = startSecond -1;
      if (startSecond == 0){
      clearInterval(codeTime);
      $("#waitCode").hide();
      $("#getCode").show();
      }
      },1000);
      $.getJSON("/data/sms/"+mobile,{} , function(ret) {
      if (ret.code == 0) {
      $("#sms").val(ret.result);
      } else {
      $.alertBoxy({ message: ret.result });
      }     
      });      
      })
      if (!placeholderSupport()) {   // 判断浏览器是否支持 placeholder
      $('[placeholder]').focus(function () {
      var input = $(this);
      if (input.val() == input.attr('placeholder')) {
      input.val('');
      input.removeClass('placeholder');
      }
      }).blur(function () {
      var input = $(this);
      if (input.val() == '' || input.val() == input.attr('placeholder')) {
      input.addClass('placeholder');
      input.val(input.attr('placeholder'));
      }
      }).blur();
      }
      ;
      $(function() {
      $(".registerButton").click(function() {
      var mobile = $("#mobile").val();
      var password = $("#password").val();
      var username = $("#username").val();
      var code = $("#code").val();
      var nickname = $("#nickname").val();
      var school = $("#school").val();
      var cls = $("#cls").val();
      var province = $("#province").val();
      var city = $("#city").val();
      var zone = $("#zone").val();
      var sms = $("#sms").val();
      if (!mobile) {
      $.alertBoxy({ message: '请填写手机号！' });
      return;
      } else {
      if (checkMobile(mobile) == false) {
      $.alertBoxy({ message: '请填写正确的手机号！' });
      return;
      }
      }
      if (!password) {
      $.alertBoxy({ message: '请填写密码！' });
      return;
      }
      if (!username) {
      $.alertBoxy({ message: '请填写用户名！' });
      return;
      } 
      if (!code) {
      $.alertBoxy({ message: '请填写手机验证码！' });
      return;
      }
      if (!sms) {
      $.alertBoxy({ message: '验证码错误！' });
      return;
      }    
      var params = [
      "password=" + encodeURIComponent(password),
      "&mobile=" + mobile,
      "&username=" + encodeURIComponent(username),
      "&code=" + encodeURIComponent(code),
      "&class=" + encodeURIComponent(cls),
      "&province=" + encodeURIComponent(province),
      "&city=" + encodeURIComponent(city),
      "&zone=" + encodeURIComponent(zone),
      "&school=" + encodeURIComponent(school),
      "&cls=" + encodeURIComponent(cls),
      "&nickname=" + encodeURIComponent(nickname),
      "&sms=" + encodeURIComponent(sms)      
      ].join('');
      var tipboxy = false;
      $.ajax({
      url: "/register",
      type: "post",
      data: params,
      dataType: "json",
      async: false,
      beforeSend: function() {
      tipboxy = $.tipsBoxy({ type: "loading", message: "数据提交中...", mask: true });
      },
      success: function(ret) {
      tipboxy.cancel();
      if (ret.code == 0) {
      $.tipsBoxy({ message: "注册成功", width: 200, height: 80 });
      setTimeout(function(){window.location.href='/login'},5000);
      } else {
      $.alertBoxy({ message: ret.result });
      }
      }
      });      
      });
      });
    script(src='/js/user/register.js')
